package gc;

/**
 * @ClassName TestBlockingThread
 * @Author ykx
 * @Date 2024/6/23 17:55
 * @Version 1.0
 */
public class TestBlockingThread {
    static Thread t1 = new Thread(() -> {

        while (true) {
            long start = System.currentTimeMillis();
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            long cost = System.currentTimeMillis() - start;

            (cost > 1010L ? System.err : System.out).printf("thread: %s, costs %d ms\n", Thread.currentThread().getName(), cost

            );

        }

    });


    static Thread t2 = new Thread(() -> {

        while (true) {

            for (int i = 1; i <= 1000000000; i++) {

                boolean b = 1.0 / i == 0;

            }


            try {

                Thread.sleep(10);

            } catch (InterruptedException e) {

                e.printStackTrace();

            }

        }

    });


    private static final int _50KB = 50 * 1024;


    //ӥᶎጱդᎱڠࣁୌय़ᰁጱ੒᨝, Ӟਧտ੕ᛘᵍӞྦྷ෸ᳵտڊሿ࣯࣍තᵞ

    static Thread t3 = new Thread(() -> {

        while (true) {

            try {

                Thread.sleep(5);

            } catch (InterruptedException e) {

                e.printStackTrace();

            }

            byte[] bytes = new byte[_50KB];

        }

    });


    public static void main(String[] args) throws InterruptedException {

        t1.start();

        Thread.sleep(1500L);

        t2.start();

        t3.start();

    }
}
